﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EasyFMS.Common
{
    /// <summary>
    /// 用于omgrid的分页
    /// </summary>
    public class PageView
    {
        /// <summary>
        /// 页面索引
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 页面记录数
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 记录起始数
        /// </summary>  
        public int RecordStart { get; set; }

        public PageView()
        {
            PageIndex = 1;
            PageSize = 10;
            RecordStart = 0;
        }

        public PageView(string pageIndex, string pageSize)
        {
            if (pageIndex != null)
            {
                try
                {
                    PageIndex = Int32.Parse(pageIndex);
                }
                catch
                {
                    PageIndex = 1;
                }

            }
            if (pageSize != null)
            {
                try
                {
                    PageSize = Int32.Parse(pageSize);
                }
                catch
                {
                    PageSize = 10;
                }
            }
        }

        public PageView(int recordStart, string pageSize)
        {
            if (pageSize != null)
            {
                try
                {
                    PageSize = Int32.Parse(pageSize);
                }
                catch
                {
                    PageSize = 10;
                }
            }
            PageIndex = (int)Math.Ceiling((double)recordStart / (double)PageSize) + 1;
        }
    }
}
